package com.huoniu.user.controller;

import com.huoniu.user.entity.TypeEnum;
import com.huoniu.user.entity.User;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @类 名： UserController <br/>
 * @描 述： <br/>
 * @日 期： 2020/9/17 9:39<br/>
 * @作 者： 侯建军<br/>
 * @版 本： 1.0.0
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/user")
@Api(value = "UserController", tags = {"用户管理"})
public class UserController {

    @GetMapping("/getUserName")
    @ApiOperation(value = "1、获取账号名称", notes = "使用账号密码登录", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "账号名称", dataType = "String",required = true),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String")})
//    public String getUserName(
//          @ApiParam(value="账号名称",required = true) String username,
//          @ApiParam("密码") String password, HttpServletRequest request) {
    public String getUserName(String username, String password, HttpServletRequest request) {
        String str = "本地端口：" + request.getLocalPort() + "远程端口：" + request.getRemotePort() + "服务端口：" + request.getServerPort();
        return "用户名为:" + username + "密码：" + password + "---->" + str;
    }

    @PostMapping(value = "/getUserData", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "username", value = "账号名称", dataType = "String")
    public User getUserData(@RequestParam String username) {
        User user = new User();
        user.setUsername(username);
        user.setPassword("123456");
        user.setId(1L);
        return user;
    }

    @PostMapping("/getUpdateUser")
    public User getUpdateUser(@RequestBody User user) {
        return user;
    }

    @PostMapping("/getUsers")
    @ApiResponse(code = 1112,message = "没有权限",responseContainer="List",response = User.class)
    // Result<List<User>>
    public List<User> getUsers(@RequestBody User user) {
        List<User> list=new ArrayList<>();
        list.add(user);
        return list;
    }

    @PostMapping("/getEnum")
    public User getEnumTest(){
        User user=new User();
        user.setUsername("admin");
        user.setTypeEnum(TypeEnum.USER);
        return user;
    }
}
